<?php

require_once ('system/application/controllers/BaseController.php');

class AjaxController extends BaseController {
	private $xml ="<?xml version=\"1.0\"?>";
	/**
	 * 
	 */
	public function __construct() {
		parent::__construct ();
		header ("Content-type: text/xml");
		header ("Cache-Control: no-cache");
	}
	
	public function _startResponse($value) {
		$this->xml .= $this->_createElement("response", $value. $this->_createElement("time", date("YmdHis")));
	}
	protected  function _createElement($name, $value) {
		return "<$name>$value</$name>";
	}
	public function _printXml() {
		echo $this->xml;
	}
	
	public function index() {
		$this->xml .= "<status>Access Denied</status>";
		echo $this->_printXml();
		
	}
	public function logIn() {
		$user = parent::_logIn();
		
		if ($user == null) {
			$this->_startResponse(
				$this->_createElement("status", 0) . 
				$this->_createElement("message", "username/password not correct. please try agan")
			);
			
		} else {
			$this->_startResponse(
				$this->_createElement("status", 1) . 
				$this->_createElement("message", "you're logged in!") .
				$this->_createElement("userid", $user->getUserID()) .
				$this->_createElement("username", $user->getUsername()) .
				$this->_createElement("password", $user->getPassword()) .
				$this->_createElement("fullname", $user->getName())
			);
		
		}
		
		
		echo $this->_printXml();

	}

}

?>
